package com.example.iot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.iot.pojo.IotDataObj;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.Map;

@Mapper
public interface IotDataMapper extends BaseMapper<IotDataObj> {

    @Select("SELECT DATE(`timestamp`) AS date,\n" +
            "       AVG(temperature) AS average_temperature\n" +
            "FROM iot_data\n" +
            "WHERE `timestamp` >= CURRENT_TIMESTAMP - INTERVAL 4 DAY\n" +
            "GROUP BY DATE(`timestamp`)\n" +
            "ORDER BY DATE(`timestamp`) DESC")
    public ArrayList<Map<String,Double>> get_average_data();
}
